package com.nkbh.sevenday.myimagethreadpool.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;

import com.nkbh.sevenday.myimagethreadpool.R;
import com.nkbh.sevenday.myimagethreadpool.adapter.MyRecycleViewAdapter;

import java.util.ArrayList;
import java.util.List;

public class RecycleViewImageActivity extends AppCompatActivity {

    RecyclerView rv;
    MyRecycleViewAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycle_view_image);
        initView();
    }

    private void initView() {
        rv=findViewById(R.id.rv);
        List<String> list=new ArrayList<>();
        list.add("https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1524216720&di=54f2665a02fb1f954432d7d361923cdf&src=http://images.17173.com/2013/news/2013/01/16/l0116hy01s.jpg");
        list.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1524226806170&di=d3965bd8a79f1da65b4b8e7b809dea6c&imgtype=0&src=http%3A%2F%2Fa3.att.hudong.com%2F51%2F79%2F300245751203132333793547052.jpg");
        list.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1524226806170&di=82c3b5c103630a560ef7dbfb868469d8&imgtype=0&src=http%3A%2F%2Fpic.nipic.com%2F2007-12-22%2F2007122210135441_2.jpg");
        list.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1524226806169&di=f58e44d6e15a9d1a4e6b5f0f79ba942b&imgtype=0&src=http%3A%2F%2Fimg5q.duitang.com%2Fuploads%2Fitem%2F201505%2F08%2F20150508155438_Lj28a.jpeg");
        list.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1524226806169&di=eca4ad04351015cbaf71142bb64aaebc&imgtype=0&src=http%3A%2F%2Fpic15.nipic.com%2F20110717%2F6906103_220347518000_2.jpg");
        list.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1524226806168&di=7be9adeca1aaa66c46ded00ab9995bfe&imgtype=0&src=http%3A%2F%2Fimg4q.duitang.com%2Fuploads%2Fitem%2F201410%2F24%2F20141024112929_xwF2H.thumb.700_0.jpeg");
        list.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1524226806166&di=7146b1ba8218a9a11aec1920167bb532&imgtype=0&src=http%3A%2F%2Fa3.topitme.com%2F9%2F51%2F6b%2F11251461040ac6b519o.jpg");
        list.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1524226806165&di=d7dea99f54033027f5a2343cd45f69a5&imgtype=0&src=http%3A%2F%2Fimg5q.duitang.com%2Fuploads%2Fitem%2F201505%2F14%2F20150514111825_KuNM3.thumb.700_0.jpeg");
        list.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1524226806165&di=e59815b30158da024e34e3314abd48f3&imgtype=0&src=http%3A%2F%2Fe.hiphotos.baidu.com%2Fzhidao%2Fpic%2Fitem%2F5366d0160924ab180bde945b36fae6cd7a890b95.jpg");
        list.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1524226806163&di=a60df5b05e741c97728415772ee27106&imgtype=0&src=http%3A%2F%2Fcdnq.duitang.com%2Fuploads%2Fitem%2F201505%2F24%2F20150524113937_zveW8.jpeg");
        list.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1524226806163&di=34e635e24d878fd0aa80831aa36b72ed&imgtype=0&src=http%3A%2F%2Fimg5q.duitang.com%2Fuploads%2Fitem%2F201406%2F26%2F20140626151319_csmEG.jpeg");
        list.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1524226806162&di=99ffa0965b413e4533e63f72918be43f&imgtype=0&src=http%3A%2F%2Fimg5.duitang.com%2Fuploads%2Fitem%2F201410%2F24%2F20141024114331_VLB3n.jpeg");


        adapter=new MyRecycleViewAdapter(RecycleViewImageActivity.this,list);

        RecyclerView.LayoutManager layoutManager = new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL);
        rv.setLayoutManager(layoutManager);
        rv.setAdapter(adapter);
        rv.addItemDecoration(new GridSpacingItemDecoration(2,10,true));
        rv.setItemAnimator(new DefaultItemAnimator());
        // use this setting to improve performance if you know that changes
        // in content do not change the layout size of the RecyclerView
        rv.setHasFixedSize(true);
    }
}
